package com.itxz.utils;

import com.itxz.handler.MyErrorHandler;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathFactory;

/**
 * Dom简单工具类
 *
 * @author ldt
 * @date 2019/12/2 16:28
 */
public class DomSimpleUtils {

    private final static DocumentBuilderFactory dbf;

    static {
        dbf = DocumentBuilderFactory.newInstance();
    }

    /**
     * 获取DOM文档建造器
     *
     * @param: []
     * @return: javax.xml.parsers.DocumentBuilder
     * @auther: ldt
     * @date: 2019/11/29 17:06
     */
    public static DocumentBuilder newDocumentBuilder(){
        try {
            DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
            // 设置错误处理器
            documentBuilder.setErrorHandler(new MyErrorHandler());
            return documentBuilder;
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e);
        }
    }
}
